// ==UserScript==
// @name           google shenghuo search
// @namespace      google
// @include        http://shenghuo.google.cn/shenghuo/search*
// ==/UserScript==

var trains = ['K372', 'T34'];
var dates = ['2009-01-17', '2009-01-18', '2009-01-19'];

function checkKeyWords(content)
{
	var isInTrains = 0;
	var isInDates = 0;
	for(var i = 0; i < trains.length; i++)
	{
		if(content.indexOf(trains[i]) >= 0)
		{
			isInTrains = 1;
			break;
		}
	}
	
	for(var i = 0; i < dates.length; i++)
	{
		if(content.indexOf(dates[i]) >= 0)
		{
			isInDates = 1;
			break;
		}
	}
	
	if(isInTrains > 0 && isInDates > 0)
		return true;
	else
		return false;
}


function parse_data()
{
	var spras;
	var sprases;

	sprases = document.evaluate(
    "//TBODY[@id='spras']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

	if(sprases.snapshotLength)
	{
		var found = 0;
		spras = sprases.snapshotItem(0);
	
		for(var i = 1; i < spras.childNodes.length; i+= 2)
		{
			var tagTD = spras.childNodes[i].childNodes[1]; // tag <TD>
			if(tagTD)
			{
				var tagA = tagTD.childNodes[1];
				var text = tagA.text;
				
				var href = tagA.href;
				if(checkKeyWords(text))
				{
					tagTD.parentNode.style.color = 'red';
					found += 1;
					GM_log("match..."+text+"\nlink = "+href);
				}
			}
		}
		
		if(found > 0)
		{
			alert("found " + found + " items in google search\nthey are all highlighted...");
			}
	}
}


parse_data();

setTimeout("window.location.href=window.location.href", 60000);// auto reload every 60 sec